export default {
  state: () => ({
    list:
      (window.localStorage.getItem("list") &&
        JSON.parse(window.localStorage.getItem("list"))) ||
      [],
  }),
  mutations: {
    SET_LOCAL_STORAGE: (state, key) => {
      console.log(state);
      window.localStorage.setItem(key, JSON.stringify(state[key]));
    },
  },
  actions: {
    addLocalLabel: ({ state, commit }, labelItem) => {
      state.list.push(labelItem);
      commit("SET_LOCAL_STORAGE", "list");
    },
    deleteLocalLabel: ({ state, commit }, labelIndex) => {
      console.log(labelIndex);
      state.list.splice(labelIndex, 1);
      commit("SET_LOCAL_STORAGE", "list");
    },
  },
};
